/**
 * 
 */
package simulation;

import java.lang.Math;
import java.util.Random;
/**
 * @author aclayton
 *
 */
public class Point {
	private double x,y;
	
	public Point(){
		x = 0;
		y = 0;
	}
	
	public Point(double x, double y){
		this.x = x;
		this.y = y;
	}
	
	public Point add(Point otherpt){
		return new Point(x+otherpt.x, y+otherpt.y);
	}
	
	public Point subtract(Point otherpt){
		return new Point(x-otherpt.x, y-otherpt.y);
	}
	
	public Point multiply(double scale){
		return new Point(x*scale, y*scale);
	}
	
	public Point getPerpendicularVector(){
		return new Point(y,-x);
	}
	
	public double getX(){
		return x;
	}
	
	public double getY(){
		return y;
	}
	
	public Point negate(){
		return new Point(-x, -y);
	}
	
	public double getDistance(Point other){
		return Math.sqrt(Math.pow(x-other.x,2)+Math.pow(y-other.y,2));
	}
	
	public double getVectorLength(){
		return Math.sqrt(x*x+y*y);
	}
	
	public Point getUnit(){
		double temp = getVectorLength();
		return new Point(x/temp, y/temp);
	}
	
	public String toString(){
		return "Pt("+x+","+y+")";
	}
	
	public static Point getRandomPointInBox(Rect boundingbox){
		Random randomGen = new Random();
		double newX = boundingbox.getWidth()*randomGen.nextDouble()+boundingbox.getLeft();
		double newY = boundingbox.getHeight()*randomGen.nextDouble()+boundingbox.getBottom();
		return new Point(newX, newY);
	}
	
	public static Point getRandomPointInCircle(Circle c){
		Random randomGen = new Random();
		
		double radian = randomGen.nextDouble() * Math.PI;
		double radius = randomGen.nextDouble() * c.getRadius();
		
		Point p = new Point(radius*Math.cos(radian)+c.getCenter().getX(), radius*Math.sin(radian)+c.getCenter().getY());
		
		return new Point(p.getX(), p.getY());
	}
	
	public static Point getRandomPointInBox(double right, double top, double left, double bottom){
		Random randomGen = new Random();
		double newX = (left-right)*randomGen.nextDouble()+right;
		double newY = (bottom-top)*randomGen.nextDouble()+top;
		return new Point(newX, newY);
	}

}
